Application programming interfaces for data parallel computing on multiple processors

ABSTRACT

A method and an apparatus for a parallel computing program calling APIs (application programming interfaces) in a host processor to perform a data processing task in parallel among compute units are described. The compute units are coupled to the host processor including central processing units (CPUs) and graphic processing units (GPUs). A program object corresponding to a source code for the data processing task is generated in a memory coupled to the host processor according to the API calls. Executable codes for the compute units are generated from the program object according to the API calls to be loaded for concurrent execution among the compute units to perform the data processing task.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of co-pending U.S. application Ser.No. 14/977,204 filed on Dec. 21, 2015, which is a continuation of U.S.application Ser. No. 14/163,404 filed Jan. 24, 2014, now issued as U.S.Pat. No. 9,250,697, which is a continuation of U.S. application Ser. No.13/646,552 filed Oct. 5, 2012, now issued as U.S. Pat. No. 8,806,513,which is a continuation of U.S. application Ser. No. 12/264,896, filedon Nov. 4, 2008, now issued as U.S. Pat. No. 8,286,198 which is relatedto, and claims the benefit of, U.S. Provisional Patent Application No.61/059,739, filed on Jun. 6, 2008 which is hereby incorporated byreference herein in its entirety.

FIELD OF INVENTION

The present invention relates generally to data parallel computing. Moreparticularly, this invention relates to application programminginterfaces (APIs) for data parallel computing across both CPUs (CentralProcessing Units) and GPUs (Graphical Processing Units).

BACKGROUND

As GPUs continue to evolve into high performance parallel computingdevices, more and more applications are written to perform data parallelcomputations in GPUs similar to general purpose computing devices.Today, these applications are designed to run on specific GPUs usingvendor specific interfaces. Thus, these applications are not able toleverage processing resources of CPUs even when both GPUs and CPUs areavailable in a data processing system. Nor can processing resources beleveraged across GPUs from different vendors where such an applicationis running.

However, as more and more CPUs embrace multiple cores to perform dataparallel computations, more and more processing tasks can be supportedby either CPUs and/or GPUs whichever are available. Traditionally, GPUsand CPUs are configured through separate programming environments thatare not compatible with each other. Most GPUs require dedicated programsthat are vendor specific. As a result, it is very difficult for anapplication to leverage processing resources of both CPUs and GPUs, forexample, leveraging processing resources of GPUs with data parallelcomputing capabilities together with multi-core CPUs.

Therefore, there is a need in modern data processing systems to overcomethe above problems to allow an application to perform a task using anyavailable processing resources, such as CPUs and one or more GPUs,capable of performing the task.

SUMMARY OF THE DESCRIPTION

An embodiment of the present invention includes methods and apparatusesfor a parallel computing program calling APIs in a host processor toperform a data processing task in parallel among compute units includingcentral processing units (CPUs) and graphic processing units (GPUs)coupled to the host processor. A program object corresponding to asource code for the data processing task is generated in a memorycoupled to the host processor according to the API calls. Executablecodes for the compute units are generated from the program objectaccording to the API calls to be loaded for concurrent execution amongthe compute units to perform the data processing task.

Other features of the present invention will be apparent from theaccompanying drawings and from the detailed description that follows.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention is illustrated by way of example and notlimitation in the figures of the accompanying drawings, in which likereferences indicate similar elements and in which:

FIG. 1 is a block diagram illustrating one embodiment of a system toconfigure computing devices including CPUs and/or GPUs to perform dataparallel computing for applications;

FIG. 2 is a block diagram illustrating an example of a computing devicewith multiple compute processors operating in parallel to executemultiple threads concurrently;

FIG. 3 is a block diagram illustrating one embodiment of a plurality ofphysical computing devices configured as a logical computing deviceusing a computing device identifier;

FIG. 4 is a flow diagram illustrating an embodiment of a process toconfigure a plurality of physical computing devices with a computingdevice identifier by matching a capability requirement received from anapplication;

FIG. 5 is a flow diagram illustrating an embodiment of a process toexecute a compute executable in a logical computing device;

FIG. 6 is a flow diagram illustrating an embodiment of a runtime processto load an executable including compiling a source for one or morephysical computing devices determined to execute the executable;

FIG. 7 is a flow diagram illustrating one embodiment of a process toselect a compute kernel execution instance from an execution queue toexecute in one or more physical compute devices corresponding to alogical computing device associated with the execution instance;

FIG. 8 is a flow diagram illustrating one embodiment of a process todetermine optimal thread group sizes to concurrently execute computekernel objects among multiple compute units;

FIG. 9A is a flow diagram illustrating one embodiment of a process tobuild an API (Application Programming Interface) library storing asource and a plurality of executables for one or more APIs in thelibrary according to a plurality of physical computing devices;

FIG. 9B is a flow diagram illustrating one embodiment of a process foran application to execute one of a plurality of executables togetherwith a corresponding source retrieved from an API library based on APIrequests;

FIG. 10 is sample source code illustrating an example of a computekernel source for a compute kernel executable to be executed in aplurality of physical computing devices;

FIGS. 11A-11C include a sample source code illustrating an example toconfigure a logical computing device for executing one of a plurality ofexecutables in a plurality of physical computing devices by callingAPIs;

FIG. 12 illustrates one example of a typical computer system with aplurality of CPUs and GPUs (Graphical Processing Unit) that can be usedin conjunction with the embodiments described herein.

DETAILED DESCRIPTION

A method and an apparatus for data parallel computing on multipleprocessors are described herein. In the following description, numerousspecific details are set forth to provide thorough explanation ofembodiments of the present invention. It will be apparent, however, toone skilled in the art, that embodiments of the present invention may bepracticed without these specific details. In other instances, well-knowncomponents, structures, and techniques have not been shown in detail inorder not to obscure the understanding of this description.

Reference in the specification to “one embodiment” or “an embodiment”means that a particular feature, structure, or characteristic describedin connection with the embodiment can be included in at least oneembodiment of the invention. The appearances of the phrase “in oneembodiment” in various places in the specification do not necessarilyall refer to the same embodiment.

The processes depicted in the figures that follow, are performed byprocessing logic that comprises hardware (e.g., circuitry, dedicatedlogic, etc.), software (such as is run on a general-purpose computersystem or a dedicated machine), or a combination of both. Although theprocesses are described below in terms of some sequential operations, itshould be appreciated that some of the operations described may beperformed in different order. Moreover, some operations may be performedin parallel rather than sequentially.

A Graphics Processing Unit (GPU) may be a dedicated graphics processorimplementing highly efficient graphics operations, such as 2D, 3Dgraphics operation and/or digital video related functions. A GPU mayinclude special (programmable) hardware to perform graphics operations,e.g. blitter operations, texture mapping, polygon rendering, pixelshading and vertex shading. GPUs are known to fetch data from a framebuffer and to blend pixels together to render an image back into theframe buffer for display. GPUs may also control the frame buffer andallow the frame buffer to be used to refresh a display, e.g. a CRT orLCD display Either a CRT or an LCD display is a short persistencedisplay that requires refresh at a rate of at least 20 Hz (e.g. every1/30 of a second, the display is refreshed with data from a framebuffer). Usually, GPUs may take graphics processing tasks from CPUscoupled with the GPUs to output raster graphics images to displaydevices through display controllers. References in the specification to“GPU” may be a graphics processor or a programmable graphics processoras described in “Method and Apparatus for Multitheraded Processing ofData In a Programmable Graphics Processor”, Lindholdm et al., U.S. Pat.No. 7,015,913, and “Method for Deinterlacing Interlaced Video by AGraphics Processor”, Swan et al., U.S. Pat. No. 6,970,206, which arehereby incorporated by reference

In one embodiment, a plurality of different types of processors, such asCPUs or GPUs may perform data parallel processing tasks for one or moreapplications concurrently to increase the usage efficiency of availableprocessing resources in a data processing system. Processing resourcesof a data processing system may be based on a plurality of physicalcomputing devices, such as CPUs or GPUs. A physical computing device mayinclude one or more compute units. In one embodiment, data parallelprocessing tasks (or data parallel tasks) may be delegated to aplurality types of processors, for example, CPUs or GPUs capable ofperforming the tasks. A data parallel task may require certain specificprocessing capabilities from a processor. Processing capabilities maybe, for example, dedicated texturing hardware support, double precisionfloating point arithmetic, dedicated local memory, stream data cache, orsynchronization primitives. Separate types of processors may providedifferent yet overlapping groups of processing capabilities. Forexample, both CPU and GPU may be capable of performing double precisionfloating point computation. In one embodiment, an application is capableof leveraging either a CPU or a GPU, whichever is available, to performa data parallel processing task.

In another embodiment, selecting and allocating a plurality of differenttypes of processing resources for a data parallel processing task may beperformed automatically during run time. An application may send a hintincluding desired list of capability requirements for a data processingtask though an API to a runtime platform of a data processing system. Inaccordance with the hint received, the runtime platform may determine aplurality of currently available CPUs and/or GPUs with capabilitiesmatching the received hint to delegate the data processing task for theapplication. In one embodiment, the list of capability requirements maydepend on the underlying data processing task. A capability requirementlist may be applicable across different groups of processors or computeunits, including, for example, GPUs and multi-core CPUs from differentvendors and of different versions. Consequently, an application may beinsulated from providing programs targeting a particular type of computeunit, such as a CPU or GPU.

Furthermore, in another embodiment, allocating and grouping multiplethreads to execute in parallel among selected compute units may beperformed according to underlying problem space for a data paralleltask. An analysis of representations for source codes to be executed inselected compute units may determine how a processing task shouldoptimally be partitioned and distributed among the selected computeunits. API interfaces may allow an application to specify how a dataparallel task should be performed by executing an executable in groupsof threads among selected compute units. In addition, an application mayretrieve, using APIs, suggestions on an optimal partitioning of a dataparallel task based on resource requirements for performing the taskamong selected compute units.

FIG. 1 is a block diagram illustrating one embodiment of a system 100 toconfigure computing devices including CPUs and/or GPUs to perform dataparallel computing for applications. System 100 may implement a parallelcomputing architecture. In one embodiment, system 100 may be a graphicssystem including one or more host processors coupled with one or morecentral processors 117 and one or more other processors such as mediaprocessors 115 through a data bus 113. The plurality of host processorsmay be networked together in hosting systems 101. The plurality ofcentral processors 117 may include multi-core CPUs from differentvendors. A compute processor or compute unit, such as CPU or GPU, may beassociated a group of capabilities. For example, a media processor maybe a GPU with dedicated texture rendering hardware. Another mediaprocessor may be a GPU supporting both dedicated texture renderinghardware and double precision floating point arithmetic. Multiple GPUsmay be connected together f or Scalable Link Interface (SLI) orCrossFire configurations.

In one embodiment, the hosting systems 101 may support a software stack.The software stack can include software stack components such asapplications 103, a compute platform layer 111, e.g. an OpenCL (OpenComputing Language) platform, a compute runtime layer 109, a computecompiler 107 and compute application libraries 105. An application 103may interface with other stack components through API calls. One or morethreads may be running concurrently for the application 103 in thehosting systems 101. The compute platform layer 111 may maintain a datastructure, or a computing device data structure, storing processingcapabilities for each attached physical computing device. In oneembodiment, an application may retrieve information about availableprocessing resources of the hosting systems 101 through the computeplatform layer 111. An application may select and specify capabilityrequirements for performing a processing task through the computeplatform layer 111. Accordingly, the compute platform layer 111 maydetermine a configuration for physical computing devices to allocate andinitialize processing resources from the attached CPUs 117 and/or GPUs115 for the processing task. In one embodiment, the compute platformlayer 111 may generate one or more logical computing devices for theapplication corresponding to one or more actual physical computingdevices configured.

The compute runtime layer 109 may manage the execution of a processingtask according to the configured processing resources for an application103, for example, based on one or more logical computing devices. In oneembodiment, executing a processing task may include creating a computeprogram object representing the processing task and allocating memoryresources, e.g. for holding executables, input/output data etc. Anexecutable loaded for a compute program object may be a compute programexecutable. A compute program executable may be included in a computeprogram object to be executed in a compute processor or a compute unit,such as a CPU or a GPU. The compute runtime layer 109 may interact withthe allocated physical devices to carry out the actual execution of theprocessing task. In one embodiment, the compute runtime layer 109 maycoordinate executing multiple processing tasks from differentapplications according to run time states of each processor, such as CPUor GPU configured for the processing tasks. The compute runtime layer109 may select, based on the run time states, one or more processorsfrom the physical computing devices configured to perform the processingtasks. Performing a processing task may include executing multiplethreads of one or more executables in a plurality of physical computingdevices concurrently. In one embodiment, the compute runtime layer 109may track the status of each executed processing task by monitoring therun time execution status of each processor.

The runtime layer may load one or more executables as compute programexecutables corresponding to a processing task from the application 103.In one embodiment, the compute runtime layer 109 automatically loadsadditional executables required to perform a processing task from thecompute application library 105. The compute runtime layer 109 may loadboth an executable and its corresponding source program for a computeprogram object from the application 103 or the compute applicationlibrary 105. A source program for a compute program object may be acompute program source. A plurality of executables based on a singlecompute program source may be loaded according to a logical computingdevice configured to include multiple types and/or different versions ofphysical computing devices. In one embodiment, the compute runtime layer109 may activate the compute compiler 107 to online compile a loadedsource program into an executable optimized for a target processor, e.g.a CPU or a GPU, configured to execute the executable.

An online compiled executable may be stored for future invocation inaddition to existing executables according to a corresponding sourceprogram. In addition, the executables may be compiled offline and loadedto the compute runtime 109 using API calls. The compute applicationlibrary 105 and/or application 103 may load an associated executable inresponse to library API requests from an application. Newly compiledexecutables may be dynamically updated for the compute applicationlibrary 105 or for the application 103. In one embodiment, the computeruntime 109 may replace an existing compute program executable in anapplication by a new executable online compiled through the computecompiler 107 for a newly upgraded version of computing device. Thecompute runtime 109 may insert a new executable online compiled toupdate the compute application library 105. In one embodiment, thecompute runtime 109 may invoke the compute compiler 107 when loading anexecutable for a processing task. In another embodiment, the computecompiler 107 may be invoked offline to build executables for the computeapplication library 105. The compute compiler 107 may compile and link acompute kernel program to generate a compute program executable. In oneembodiment, the compute application library 105 may include a pluralityof functions to support, for example, development toolkits and/or imageprocessing. Each library function may correspond to a compute programsource and one or more compute program executables stored in the computeapplication library 105 for a plurality of physical computing devices.

FIG. 2 is a block diagram illustrating an example of a computing devicewith multiple compute processors (e.g. compute units) operating inparallel to execute multiple threads concurrently. Each computeprocessor may execute a plurality of threads in parallel (orconcurrently). Threads that can be executed in parallel in a computeprocessor or compute unit may be referred to as a thread group. Acomputing device could have multiple thread groups that can be executedin parallel. For example, M threads are shown to execute as a threadgroup in computing device 205. Multiple thread groups, e.g. thread 1 ofcompute processor_1 205 and thread N of compute processor_L 203, mayexecute in parallel across separate compute processors on one computingdevice or across multiple computing devices. A plurality of threadgroups across multiple compute processors may execute a compute programexecutable in parallel. More than one compute processors may be based ona single chip, such as an ASIC (Application Specific Integrated Circuit)device. In one embodiment, multiple threads from an application may beexecuted concurrently in more than one compute processors acrossmultiple chips.

A computing device may include one or more compute processors or computeunits such as Processor_1 205 and Processor_L 203. A local memory may becoupled with a compute processor. Local memory, shared among threads ina single thread group running in a compute processor, may be supportedby the local memory coupled with the compute processor. Multiple threadsfrom across different thread groups, such as thread 1 213 and thread N209, may share a compute memory object, such as a stream, stored in acomputing device memory 217 coupled to the computing device 201. Acomputing device memory 217 may include a global memory and a constantmemory. A global memory may be used to allocate compute memory objects,such as streams. A compute memory object may include a collection ofdata elements that can be operated on by a compute program executable. Acompute memory object may represent an image, a texture, a frame-buffer,an array of a scalar data type, an array of a user-defined structure, ora variable, etc. A constant memory may be read-only memory storingconstant variables frequently used by a compute program executable.

In one embodiment, a local memory for a compute processor or computeunit may be used to allocate variables shared by all thread in a threadgroup or a thread group. A local memory may be implemented as adedicated local storage, such as local shared memory 219 for Processor_1and local shared memory 211 for Processor_L. In another embodiment, alocal memory for a compute processor may be implemented as a read-writecache for a computing device memory for one or more compute processorsof a computing device, such as data cache 215 for compute processors205, 203 in the computing device 201. A dedicated local storage may notbe shared by threads across different thread groups. If the local memoryof a compute processor, such as Processor_1 205 is implemented as aread-write cache, e.g. data cache 215, a variable declared to be in thelocal memory may be allocated from the computing device memory 217 andcached in the read-write cache, e.g. data cache 215, that implements thelocal memory. Threads within a thread group may share local variablesallocated in the computing device memory 217 when, for example, neithera read-write cache nor dedicated local storage are available for thecorresponding computing device. In one embodiment, each thread isassociated with a private memory to store thread private variables thatare used by functions called in the thread. For example, private memory1 211 may not be seen by threads other than thread 1 213.

FIG. 3 is a block diagram illustrating one embodiment of a plurality ofphysical computing devices configured as a logical computing deviceusing a computing device identifier. In one embodiment, an application303 and a platform layer 305 may be running in a host CPU 301. Theapplication 303 may be one of the applications 103 of FIG. 1. Hostingsystems 101 may include the host CPU 301. Each of the physical computingdevices Physical_Compute_Device-1 305 through Physical_Compute_Device-N311 may be one of the CPUs 117 or GPUs 115 of FIG. 1. In one embodiment,the compute platform layer 111 may generate a computing deviceidentifier 307 in response to API requests from the application 303 forconfiguring data parallel processing resources according to a list ofcapability requirements included in the API requests. The computingdevice identifier 307 may refer to a selection of actual physicalcomputing devices Physical_Compute_Device-1 305 throughPhysical_Compute_Device-N 311 according to the configuration by thecompute platform layer 111. In one embodiment, a logical computingdevice 309 may represent the group of selected actual physical computingdevices separate from the host CPU 301.

FIG. 4 is a flow diagram illustrating an embodiment of a process 400 toconfigure a plurality of physical computing devices with a computedevice identifier by matching a capability requirement received from anapplication. Exemplary process 400 may be performed by a processinglogic that may comprise hardware (circuitry, dedicated logic, etc.),software (such as is run on a dedicated machine), or a combination ofboth. For example, process 400 may be performed in accordance with thesystem 100 of FIG. 1 in a data processing system hosted by the hostingsystems 101. The data processing system may include a host processorhosting a platform layer, such as compute platform layer 111 of FIG. 1,and multiple physical computing devices attached to the host processor,such as CPUs 117 and GPUs 115 of FIG. 1.

At block 401, in one embodiment, the processing logic of process 400 maybuild a data structure (or a computing device data structure)representing multiple physical computing devices associated with one ormore corresponding capabilities. Each physical computing device may beattached to the processing system performing the processing logic ofprocess 400. Capabilities or compute capabilities of a physicalcomputing device, such as CPU or GPU, may include whether the physicalcomputing device support a processing feature, a memory accessingmechanism, a named extension or associated limitations. A processingfeature may be related to dedicated texturing hardware support, doubleprecision floating point arithmetic or synchronization support (e.g.mutex).

Capabilities of a computing device may include a type indicatingprocessing characteristics or limitations associated with a computingdevice. An application may specify a type of required computing deviceor query the type of a specific computing device using APIs. Examples ofdifferent types of computing devices are shown in the following table:

TABLE 1 cl_device_type Description CL_DEVICE_TYPE_CPU A single ormulti-core CPU computing device may act as the host processor. The hostCPU may host the application and OpenCL runtime. CL_DEVICE_TYPE_GPU Acomputing device that may also be used as a GPU, for example, toaccelerate a 3D API such as OpenGL or DirectX.CL_DEVICE_TYPE_ACCELERATOR Dedicated compute accelerators other thanCPUs or GPUs such as DSPs (digital signal processors), DAXPY (doubleprecision a times x plus y) accelerators etc. CL_DEVICE_TYPE_ALL Allcomputing devices available in the system.

Additionally, capabilities of a computing device may include, forexample, configuration values as shown in the following table:

TABLE 2 cl_device_config_info Description CL_DEVICE_TYPE Computingdevice type. Currently supported values are: CL_DEVICE_TYPE_CPU,CL_DEVICE_TYPE_GPU, CL_DEVICE_TYPE_ACCELERATOR, or a combination of theabove. CL_DEVICE_MAX_COMPUTE_UNITS The number of parallel compute unitson the computing device. The minimum value is one.CL_DEVICE_MAX_THREAD_DIMENSIONS Maximum dimensions that specify theglobal and local thread IDs. The minimum value is 3.CL_DEVICE_MAX_GLOBAL_THREAD_SIZE Max number of global threads that canbe specified. CL_DEVICE_MAX_THREAD_GROUP_SIZE Max number of threads in athread group CL_DEVICE_SIMD_THREAD_GROUP_SIZE Each thread group may besplit into a SIMD group of threads. The number of threads in this SIMDgroup is given by this token. The threads in each SIMD group areexecuted in a SIMD fashion. If the size of the SIMD group is n, then thefirst n threads of the thread group will be executed by SIMD group 0,the next n threads will be executed by SIMD group 1 etc . . .CL_DEVICE_CLOCK_FREQUENCY Computing device clock frequency in MHz.CL_DEVICE_ADDRESS_SPACE_BITS Computing device address space sizespecified as an unsigned integer value in bits, for example, 32 or 64bits. CL_DEVICE_MAX_READ_IMAGE_ARGS Max number of simultaneous imagememory objects that can be read by a compute kernel.CL_DEVICE_MAX_WRITE_IMAGE_ARGS1 Max number of simultaneous image memoryobjects that can be written to by a compute kernel. The minimum value is0 if the computing device does not support formatted image writes. Ifformatted image writes are supported, the minimum value is 8.CL_DEVICE_MAX_MEM_ALLOC_SIZE Max size of memory object allocation inbytes. The minimum value is max (¼_(th) of CL_DEVICE_GLOBAL_MEM_SIZE,128 * 1024 * 1024) CL_DEVICE_IMAGE2D_MAX_WIDTH Max width of 2D image inpixels. The minimum value is 8192. CL_DEVICE_IMAGE3D_MAX_WIDTH Max widthof 3D image in pixels. The minimum value is 1024.CL_DEVICE_IMAGE3D_MAX_HEIGHT Max height of 3D image in pixels. Theminimum value is 1024. CL_DEVICE_IMAGE3D_MAX_DEPTH Max depth of 3D imagein pixels. The minimum value is 1024 CL_DEVICE_MAX_SAMPLERS Maximumnumber of samplers that can be used in a compute kernel. A minimum valuemay be 16. A sampler may include address mode, filter mode andnormalized coordinates for a multi-dimensional object.CL_DEVICE_MAX_SAMPLERS Maximum number of samplers that can be used in acompute kernel. A minimum value may be 16 CL_DEVICE_MEM_BASE_ADDR_ALIGNDescribes the alignment in bits for the base address of any allocatedmemory object. CL_DEVICE_IMAGE_PITCH_ALIGN Describes pitch alignmentrequirements in bits for an image memory object.CL_DEVICE_IMAGE_MIN_PITCH_SIZE This is the smallest pitch size in bytesallowed for any image memory object. CL_DEVICE_SINGLE_FP_CONFIGDescribes single precision floating point capability of the computingdevice. This is a bit-field that describes one or more of the followingvalues: CL_FP_DENORM - denorms are supported CL_FP_INF_NAN - INF andNaNs are supported. CL_FP_ROUND_TO_NEAREST - nearest rounding modesupported CL_FP_ROUND_TO_ZERO - round to zero rounding mode supportedCL_FP_ROUND_TO_INF - round to +ve and −ve infinity rounding modessupported CL_FP_FMA - IEEE754r fused multiply-add is supported Themandated minimum floating point capability may include:CL_FP_ROUND_TO_NEAREST| CL_FP_INF_NAN. CL_DEVICE_GLOBAL_MEM_CACHE_TYPEType of global memory cache supported, such as CL_NONE, CL_READ andCL_READ_WRITE. CL_DEVICE_GLOBAL_MEM_CACHE_LINE_SIZE Size of globalmemory cache line in bytes. CL_DEVICE_GLOBAL_MEM_CACHE_SIZE Size ofglobal memory cache in bytes. CL_DEVICE_GLOBAL_MEM_SIZE Size of globaldevice memory in bytes. CL_DEVICE_GLOBAL_GART_MEM_SIZE Size of hostaccessible (PCIe) memory in bytes CL_DEVICE_CONSTANT_MEM_SIZE Size ofconstant memory arena in bytes CL_DEVICE_LOCAL_MEM_TYPE The type oflocal memory that is available. For example, a CL_LOCAL value may implydedicated local memory storage such as SRAM, or CL_GLOBAL.CL_DEVICE_LOCAL_MEM_SIZE Size of local memory arena in bytes.CL_DEVICE_PROFILING_TIMER_RESOLUTION Describes the resolution ofcomputing device timer. This is measured in nanoseconds.CL_DEVICE_EXTENSIONS A string describing optional features supported,such as 64 bit floating point arithmetic operations, 64 bit integerarithmetic operations, 3D image writes, complex numbers, local atomics,etc.

A memory accessing mechanism for a physical processing device may berelated to a type of variable cache (e.g., no support, read-only, orread-write), a type of compute memory object cache, size of cachesupport, a dedicated local memory support or associated limitations.Memory accessing limitations may include a maximum number of computememory objects that can be simultaneously read or written by a computeprogram executable, a maximum number of compute memory objects that canbe allocated, or a maximum size along a dimension of a multi-dimensionalcompute memory object, for example, a maximum width of a compute memoryobject for a 2D (two-dimensional) image. A system application of thedata processing system may update the data structure in response toattaching a new physical computing device to a data processing system.In one embodiment, the capabilities of a physical computing device maybe predetermined. In another embodiment, a system application of thedata processing system may discover a newly attached physical processingdevice during run time. The system application may retrieve thecapabilities of the newly discovered physical computing device to updatethe data structure representing the attached physical computing devicesand their corresponding capabilities.

According to one embodiment, the processing logic of process 400 mayreceive a compute capability requirement from an application at block403. The application may send the compute capability requirement to asystem application by calling APIs. The system application maycorrespond to a platform layer of a software stack in a hosting systemfor the application. In one embodiment, a compute capability requirementmay identify a list of required capabilities for requesting processingresources to perform a task for the application. In one embodiment, theapplication may require the requested processing resources to performthe task in multiple threads concurrently. In response, the processinglogic of process 400 may select a group of physical computing devicesfrom attached physical computing devices at block 405. The selection maybe determined based on a matching between the compute capabilityrequirement against the compute capabilities stored in the capabilitydata structure. In one embodiment, the processing logic of process 400may perform the matching according to a hint provided by the capabilityrequirement.

The processing logic of process 400 may determine a matching scoreaccording to the number of compute capabilities matched between aphysical computing device and the compute capability requirement. In oneembodiment, the processing logic of process 400 may select multiplephysical computing devices with highest matching scores. In anotherembodiment, the processing logic of process 400 may select a physicalcomputing device if each capability in the capability requirement ismatched. The processing logic of process 400 may determine multiplegroups of matching physical computing devices at block 405. In oneembodiment, each group of matching physical computing devices areselected according to a load balancing capability of each device. Atblock 407, in one embodiment, the processing logic of process 400 maygenerate a computing device identifier for each group of physicalcomputing devices selected at block 405. The processing logic of process400 may return one or more of the generated computing device identifiersback to the application through the calling APIs. An application maychoose which processing resources to employ for performing a taskaccording to the computing device identifiers. In one embodiment, theprocessing logic of process 400 may generate at most one computingdevice identifier at block 407 for each capability requirement received.

At block 409, in one embodiment, the processing logic of process 400 mayallocate resources to initialize a logical computing device for a groupof physical computing devices selected at block 405 according to acorresponding computing device identifier. A logical computing devicemay be a computing device group including one or more physical computingdevices. The processing logic of process 400 may perform initializing alogical computing device in response to API requests from an applicationwhich has received one or more computing device identifiers according tothe selection at block 405. The processing logic of process 400 maycreate a context object on the logical computing device for anapplication. Commands that operate on compute memory object, computeprogram objects and/or compute program executables for a context objectmay be executed in-order (e.g. synchronously) or out of order (e.g.asynchronously) according to parameters specified in API requests whencreating the context object. Profiling commands that operate on computememory objects, compute programs or compute kernels may be enabled for acontext object using API requests. In one embodiment, a context objectis associated with one application thread in a hosting system runningthe application. Multiple threads performing processing tasks in onelogical computing device or across different logical computing devicesconcurrently may be based on separate context objects.

In one embodiment, the processing logic of process 400 may be based onmultiple APIs including clCreateContext, clRetainContext andclReleaseContext. The API clCreateContext creates a compute context. Acompute context may correspond to a compute context object. The APIclRetainContext increments the number of instances using a particularcompute context identified by a context as an input argument toclRetainContext. The API clCreateContext does an implicit retain. Thisis very helpful for third-party libraries, which typically get a contextpassed to them by the application. However, it is possible that theapplication may delete the context without informing the library.Allowing multiple instances to attach to a context and release from acontext solves the problem of a compute context being used by a libraryno longer being valid. If an input argument to clRetainContext does notcorrespond to a valid compute context object, clRetainContext returnsCU_INVALID_CONTEXT. The API clReleaseContext releases an instance from avalid compute context. If an input argument to clReleaseContext does notcorrespond to a valid compute context object, clReleaseContext returnsCU_INVALID_CONTEXT.

FIG. 5 is a flow diagram illustrating an embodiment of an exampleprocess 500 to execute a compute executable in a logical computingdevice. In one embodiment, process 500 may be performed by a runtimelayer in a data processing system such as the compute runtime layer 109of FIG. 1. At block 501, the processing logic of process 500 mayallocate one or more compute memory objects (e.g. streams) in a logicalcomputing device to execute a compute executable. A compute memoryobject may include one or more data elements to represent, for example,an image memory object or an array memory object. An array memory objectmay be a one-dimensional collection of data element. An image memoryobject may be a collection to store two-dimensional, three-dimensionalor other multi-dimensional data, such as a texture, a frame buffer or animage. A processing task may be performed by a compute programexecutable operating on compute memory objects or streams using computememory APIs including reading from input compute memory objects andwriting to output compute memory objects. In one embodiment, a computememory object may be attached to a data object, such as a buffer object,texture object or a render buffer object, for updating the data objectusing compute memory APIs. A data object may be associated with APIsthat activate graphics data processing operations, such as textrendering, on the data object.

When allocating a compute memory object, the processing logic of process500 may determine where the allocation should reside according tospecifications in an API. For example, a compute memory object may beallocated out of a host memory, such as a host memory for the hostingsystems 101 of FIG. 1 and/or a computing device memory, such as a globalmemory or a constant memory 217 of FIG. 2. A compute memory objectallocated in a host memory may need to be cached in a computing devicememory. The processing logic of process 500 may asynchronously load datainto allocated compute memory objects using non blocking API interfaces,e.g. based on generated event objects which include synchronization dataindicating whether data has been loaded into a compute memory object. Inone embodiment, the processing logic of process 500 may schedule memoryaccess operations when reading from or writing to allocated computememory objects. The processing logic of process 500 may map an allocatedstream memory to form a logical address of an application. In oneembodiment, the processing logic of process 500 may perform operationsat block 501 based API requests from an application running in a hostprocessor, such as applications 103 of FIG. 1.

At block 503, according to one embodiment, the processing logic ofprocess 500 may create a compute program object for the logicalcomputing device (e.g. a computing device group). A compute programobject may include a group of compute kernels representing exportedfunctions or entry points of a data parallel program. A compute kernelmay include a pointer to a compute program executable that can beexecuted on a compute unit to perform a data parallel task (e.g. afunction). Each compute kernel may be associated with a group offunction arguments including compute memory objects or streams allocatedfor function inputs or outputs, such as the streams allocated at block501.

The processing logic of process 500 may load a compute program binaryand/or a compute program source into the compute program object at block509. A compute program binary may include bits that describe a computeprogram executable that will be run on a computing device. A computeprogram binary may be a compute program executable and/or anintermediate representation of a compute program source to be convertedinto a compute program executable. In one embodiment, a compute programexecutable may include description data associated with, for example,the type of target physical computing devices (e.g. a GPU or a CPU),versions, and/or compilation options or flags, such as a thread groupsizes and/or thread group dimensions. A compute program source may bethe source code where a compute program executable is compiled from. Theprocessing logic of process 500 may load multiple compute programexecutables corresponding to a compute program source at block 509. Inone embodiment, the processing logic of process 500 may load a computeprogram executable from an application or through a compute library suchas compute application library 105 of FIG. 1. A compute programexecutable may be loaded with the corresponding compute program source.The processing logic of process 500 may set up function arguments for acompute program object at block 505. In one embodiment, the processinglogic of process 500 may perform operations at blocks 503, 505 and 509according to API requests from an application.

At block 511, the processing logic of process 500 may update anexecution queue to execute the compute kernel object with a logicalcomputing device. The processing logic of process 500 may execute acomputer kernel in response to API calls with appropriate arguments to acompute runtime, e.g. compute runtime 109 of FIG. 1, from an applicationor a compute application library, such as applications 103 or computeapplication library 105 of FIG. 1. Executing a compute kernel mayinclude executing a compute program executable associated with thecompute kernel. In one embodiment, the processing logic of process 500may generate a compute kernel execution instance to execute a computekernel. API calls to a compute runtime, such as compute runtime 109 ofFIG. 1, to execute a compute kernel may be asynchronous in nature. Anexecution instance may be identified by a compute event object that maybe returned by a compute runtime, such as compute runtime 109 of FIG. 1.A compute kernel execution instance may be added to an execution queueto execute a compute kernel instance.

In one embodiment, API calls to a compute runtime to execute a computekernel may include the number of threads that execute simultaneously inparallel on a compute processor as a thread group. An API call mayinclude the number of compute processors to use. A compute kernelexecution instance may include a priority value indicating a desiredpriority to execute the corresponding compute program executable. Acompute kernel execution instance may also include an event objectidentifying a previous execution instance and/or expected total numberof threads and number of thread groups to perform the execution. Thenumber of thread groups and total number of threads may be specified inthe API calls. In one embodiment, an event object may indicate anexecution order relationship between the execution instance thatincludes the event object and another execution instance identified bythe event object. An execution instance including an event object may berequired to be executed after another execution instance identified bythe event object finishes execution. An event object may be referred toas a queue_after_event_object. In one embodiment, an execution queue mayinclude multiple compute kernel execution instances for executingcorresponding compute program executables. One ore more compute kernelexecution instances for a compute program executable may be scheduledfor execution in an execution queue. In one embodiment, the processinglogic of process 500 may update the execution queue in response to APIrequests from an application. The execution queue may be hosted by thehosting data systems where the application is running.

At block 513, the processing logic of process 500 may select a computekernel execution instance from the execution queue for execution. In oneembodiment, the processing logic of process 500 may select more than onecompute kernel execution instances to be executed concurrently accordingto the corresponding logical computing devices. The processing logic ofprocess 500 may determine whether a compute kernel execution instance isselected from the execution queue based on its associated priority anddependency relationships with other execution instances in the executionqueue. A compute kernel execution instance may be executed by executingits corresponding compute kernel object according to an executableloaded to the compute kernel object.

At block 517, in one embodiment, the processing logic of process 500 mayselect one of the plurality of executables loaded to the compute kernelobject corresponding to the selected compute kernel instance forexecution in a physical computing device associated with the logicalcomputing device for the compute kernel object. The processing logic ofprocess 500 may select more than one executables to be executed in morethan one physical computing devices in parallel for one compute kernelexecution instance. The selection may be based on current executionstatuses of the physical computing devices corresponding to the logicalcomputing device associated with the selected compute kernel executioninstance. An execution status of a physical computing device may includethe number of threads running, the local memory usage level and theprocessor usage level (e.g. peak number of operations per unit time)etc. In one embodiment, the selection may be based on predeterminedusage levels. In another embodiment, the selection may be based on thenumber of threads and number of thread groups associated with thecompute kernel execution instance. The processing logic of process 500may retrieve an execution status from a physical computing device. Inone embodiment, the processing logic of process 500 may performoperations to select a compute kernel execution instance from theexecution queue to execute at blocks 513 517 asynchronously toapplications running in hosting systems.

At block 519, the processing logic of process 500 may check theexecution status of a compute kernel execution instance scheduled forexecution in the execution queue. Each execution instance may beidentified by a unique compute event object. An event object may bereturned to an application or a compute application library, such asapplication 103 or compute application library 105 of FIG. 5, whichcalls APIs to execute the execution instance, when the correspondingcompute kernel execution instance was queued according to a computeruntime, such as the runtime 109 of FIG. 1. In one embodiment, theprocessing logic of process 500 may perform the execution statuschecking in response to API requests from an application. The processinglogic of process 500 may determine the completion of executing a computekernel execution instance by querying a status of the compute eventobject identifying the compute kernel execution instance. The processinglogic of process 500 may wait until the execution of a compute kernelexecution instance is complete to return to API calls from anapplication. The processing logic of process 500 may control processingexecution instances reading and/or writing from various streams based oncompute event objects.

At block 521, according to one embodiment, the processing logic ofprocess 500 may retrieve results of executing a compute kernel executioninstance. Subsequently, the processing logic of process 500 may clean upprocessing resources allocated for executing the compute kernelexecution instance. In one embodiment, the processing logic of process500 may copy a stream memory holding results of executing a computekernel executable into a local memory. The processing logic of process500 may delete variable streams or image streams allocated at block 501.The processing logic of process 500 may delete a kernel event object fordetecting when a compute kernel execution is completed. If each computekernel execution instance associated with a specific compute kernelobject has been completely executed, the processing logic of process 500may delete the specific compute kernel object. In one embodiment, theprocessing logic of process 500 may perform operations at block 521based on API requests initiated by an application.

FIG. 6 is a flow diagram illustrating an embodiment of a runtime process600 to load an executable including compiling a source for one or morephysical computing devices determined to execute the executable. Process600 may be performed as part of process 500 at block 507 of FIG. 5. Inone embodiment, process 600 may select, for each physical computingdevice associated with a logical computing device, one or more existingcompute kernel executables compatible with the physical computing deviceat block 601. A compute kernel executable may be executed in acompatible physical computing device. The existing compute kernelexecutables may be available from an application or through a computelibrary such as compute application library 105 of FIG. 1. Each of theselected compute kernel executables may be executed by at least onephysical computing device. In one embodiment, the selection may be basedon the description data associated with the existing compute kernelexecutables.

If there are existing compute kernel objects selected, process 600 maydetermine if any of the selected compute kernel executables is optimizedfor a physical computing device at block 603. The determination may bebased on, for example, the version of the physical computing device. Inone embodiment, process 600 may determine that an existing computekernel executable is optimized for a physical computing device if theversion of target physical computing device in the description datamatches the version of the physical computing device.

At block 605, in one embodiment, process 600 may build a new computekernel executable optimized for a physical computing device from thecorresponding computer kernel source using an online compiler, such ascompute compiler 107 of FIG. 1. Process 600 may perform the online buildif none of the selected compute kernel executables are found to beoptimized for the physical computing device at block 603. In oneembodiment, process 600 may perform the online build if none of existingcompute kernel executables are found to be compatible with the physicalcomputing device at block 601. The compute kernel source may beavailable from an application or through a compute library, such ascompute application library 105 of FIG. 1.

If the build at block 605 is successful, in one embodiment, process 600may load the newly built compute kernel executable into thecorresponding compute kernel object at block 607. Otherwise, process 600may load the selected compute kernel executables to the kernel object atblock 609. In one embodiment, process 600 may load a compute kernelexecutable to a compute kernel object if the compute kernel executablehas not yet been loaded. In another embodiment, process 600 may generatean error message if none of existing compute kernel executables for acompute kernel object are compatible with a physical computing deviceand the corresponding compute kernel source is not available.

FIG. 7 is a flow diagram illustrating one embodiment of a process 700 toselect a compute kernel execution instance from an execution queue toexecute in one or more physical computing devices corresponding to alogical computing device associated with the execution instance. Process700 may be performed as part of process 500 at block 513 of FIG. 5. Inone embodiment, process 700 may identify dependency conditions amongcompute kernel execution instances currently scheduled in an executionqueue at block 701. A dependency condition of compute kernel executioninstance may prevent execution of a compute kernel execution instance ifthe condition is outstanding. In one embodiment, a dependency conditionmay be based on relationships between input streams fed by outputstreams. In one embodiment, process 700 may detect a dependencycondition between execution instances according to input streams andoutput streams of the corresponding functions for the executioninstances. In another embodiment, an execution instance with lowerpriority level may have a dependency relationship with another executionwith high priority level.

At block 703, in one embodiment, process 700 may select a compute kernelexecution instances for execution from multiple scheduled compute kernelexecution instances without any outstanding dependency condition. Theselection may be based on a priority level assigned to an executioninstance. In one embodiment, the selected compute kernel executioninstance may be associated the highest priority level among theplurality of compute kernel execution instances without outstandingdependency conditions. At block 705, process 700 may retrieve a currentexecution statuse for one or more of the physical computing devicescorresponding to the selected compute kernel execution instance. In oneembodiment, execution status of a physical computing device may beretrieved from predetermined memory locations. In another embodiment,process 700 may send a status request to a physical computing device toreceive an execution status report. Process 700 may designate one ormore of the physical computing devices to execute the selected computekernel execution instance based on the retrieved execution statuses atblock 707. In one embodiment, a physical computing device may bedesignated for execution according to a load balancing considerationwith other physical computing devices. The selected physical computingdevice may be associated with an execution status satisfying one or morespecified (e.g. predetermined) criteria, such as below a predeterminedprocessor usage level and/or memory usage level. In one embodiment, thepredetermined criteria may depend on the number of threads and thenumber of thread groups associated with the selected compute kernelexecution instance. Process 700 may load separate compute kernelexecutables for the same execution instance or multiple instances to oneor more designated physical computing devices to execute in parallel inmultiple threads.

FIG. 8 is a flow diagram illustrating one embodiment of a process 800 todetermine optimal thread group sizes to concurrently execute computekernel objects among multiple compute units. Exemplary process 800 maybe performed by a processing logic that may comprise hardware(circuitry, dedicated logic, etc.), software (such as is run on adedicated machine), or a combination of both. For example, process 800may be performed by some components of system 100 of FIG. 1 or as partof process 500 at block 523 of FIG. 5. In one embodiment, at block 801the processing logic of process 800 may determine resource requirementsfrom executable codes compiled from a single source targeting differentcompute units. Resource requirements of an executable code may includeusage data on registers, memories and/or other hardware components for atarget compute unit for the executable code. A single source may becompiled into different executable codes loaded into different types ofcompute units to perform a data parallel task (or function) specified bythe single source. In some embodiments, the processing logic of process800 may determine resource requirements based on a source code and atarget compute unit for executing instructions compiled from the sourcecode.

The processing logic of process 800 may analyze (and/or traverse) anintermediate representation of executable codes compiled from a sourcecode targeting a compute unit to determine required resources to executethe executable codes in the target compute unit. During the analysis,the processing logic of process 800 may identify a portion of a sourcecode based on matching optimization conditions to recompile theidentified portion of the source code to reduce the required resourcesfor execution in the target compute unit. For example, the processinglogic of process 800 may replace a variable in a source code with aconstant value The processing logic of process 800 may identify adimension of a data parallel task according to an analysis of thecorresponding executable codes. When an identified dimension differsfrom a dimension specified, for example, using APIs, the processinglogic of process 800 may select one of the identified dimension and thespecified dimension according to, for example, a system setting.

At block 803, in some embodiment, the processing logic of process 800may determine optimal thread group sizes for executing executable codesin parallel among multiple compute units according to the determinedresource requirements. A group of threads may execute an executable codecompiled concurrently in a target compute unit. An optimal thread groupsize may be the number of threads in a thread group to execute anexecutable code in a compute unit to maximize resource usage within thecompute unit. Resource usage of a compute unit may be measured in termsof the amount of time to accomplish a data parallel task. In someembodiments, the processing logic of process 800 may retrieve currentresource usage status from a compute unit to determine an optimal threadgroup size for an executable code. An optimal thread group size may bebased on a dimension associated with the data parallel task for anexecutable code to perform. A dimension may be a number specifying aniterative computation along more than one measures for a data paralleltask. For example, an image processing task may be associated with adimension of 2 along an image width and an image height.

At block 805, according to one embodiment, the processing logic ofprocess 800 may determine a total number of threads to execute inparallel among multiple compute units one or more executable codes (orcompute kernels) compiled from a single source to accomplish a dataparallel task (or function). The processing logic of process 800 mayreceive an API request from an application running in a host processor(or host processing unit), such as applications 103 in hosting systems101 of FIG. 1. An API request may include a global thread number havinga multi-dimensional value as an array of N integers (G₁, G₂, . . . ,G_(N)). Integer N may be a dimension associated with the data paralleltask. The processing logic of process 800 may count the number ofintegers in an array from a multi-dimensional value to determine adimension. In response to the API request, the processing logic ofprocess 800 may determine the total number of threads that will executethe executable codes among the multiple compute units according to aproduct of N integers as G₁*G₂* . . . *G_(N).

In one embodiment, the processing logic of process 800 may verifywhether a local thread group number has been specified at block 807. Alocal thread group number may have a multi-dimensional value specifiedas an array of N integers (L₁, L₂, . . . , L_(N)). In one embodiment,the dimension of a local thread group number may be equal to thedimension of a total thread number for performing a data parallel task.The processing logic of process 800 may retrieve a local thread groupnumber from a program kernel object which is associated with a sourcecode and/or an executable code compiled from the source code for atarget compute unit. In one embodiment, a local thread group number maybe specified using APIs to compile a source code. If a local threadgroup number can be retrieved, the processing logic of process 800 mayverify the local thread group number has already been specified. In someembodiments, a local thread group number may be specified using an APIrequest from an application running in a hosting processor. An APIrequest may include both a multi-dimensional global thread number and amulti-dimensional local thread group number.

At block 809, if a local thread group number has been specified, theprocessing logic of process 800 may designate a thread group size for acompute unit according the specified local thread group number. In oneembodiment, a thread group size corresponding to a local thread groupnumber having a multi-dimensional value (L₁, L₂, . . . , L_(N)) may beequal to a product of N integers as L₁*L₂* . . . *L_(N). Executablecodes compiled for different compute units may be associated withdifferent local thread group numbers. If a local thread group number hasbeen specified for an executable code, the processing logic of process800 may designate thread group sizes according to determined optimalthread group sizes for multiple compute units, such as, for example,based on the determination of optimal thread group sizes at block 803.

The processing logic of process 800 may check the designated threadgroup sizes against allowable thread group sizes during run time for thetarget compute units. For example, a compute unit may be limited by amaximum runtime thread group size depending on available resources. Theprocessing logic of process 800 may adjust designated thread group sizesto satisfy the runtime resource constraints of targeting computingdevices. In some embodiment, the processing logic of process 800 mayperform the determination to identify optimal thread group sizes atblock 811 when a multi-dimensional local thread group number has notbeen specified.

At block 813, the processing logic of process 800 may partition thetotal number of threads according to thread group sizes to executeconcurrently in multiple compute units for a data parallel task. Anexecutable code may execute in parallel in a compute unit as a group ofthreads having a size equal to the corresponding thread group size. Thesize of a group of threads may be the number of threads in the group.The processing logic of process 800 may decompose a data parallel taskinto appropriate multi-dimensional blocks or thread groups that can beexecuted concurrently across one or more compute units.

In one embodiment, a thread that executes an executable code may beidentified by two distinct thread variables, a global thread ID(identifier) and a local thread ID. A global thread ID may be specifiedwith a multi-dimensional value starting at (0, 0, . . . , 0) and goes to(G₁−1, G₂−1, . . . , G_(N)−1) based on a global thread number (G₁, G₂, .. . , G_(N)). Similarly, a local thread ID may be specified with amulti-dimensional value starting at (0, 0, . . . , 0) and goes to (L₁−1,L₂−1, . . . , L_(N)−1) based on a local thread group number (L₁, L₂, . .. , L_(N)). A global thread ID and a local thread ID for a thread may bemulti-dimensional values of the same dimension.

FIG. 9A is a flow diagram illustrating one embodiment of a process 900Ato build an API library storing a source and multiple executables forone or more APIs in the library according to multiple physical computingdevices. Process 900A may be performed offline to load a source code foran API function into a data processing system at block 901. The sourcecode may be a compute kernel source to be executed in one or morephysical computing devices. In one embodiment, process 900A maydesignate multiple target physical computing devices for the APIfunction at block 903. A target physical computing device may bedesignated according to types, such as CPU or GPU, versions or vendors.Process 900A may compile the source code into an executable, such as acompute kernel executable, for each designated target physical computingdevice at block 905. In one embodiment, process 900A may perform thecompilation offline based on an online compiler, such as computecompiler 107 of FIG. 1.

At block 907, process 900A may store the source code of the API functioninto an API library with corresponding executables compiled for thedesignated target physical computing devices. One or more API functionsfor a single executable may be exported from an API library toaccommodate source codes of host applications, such as applications 103of FIG. 1, running in a host processor. For example, an application mayexecute executable codes (or compute kernel) using OpenCL API as aregular “C” function call. In one embodiment, each executable may bestored with description data including, for example, the type, versionand vendor of the target physical computing device and/or compilationoptions. The description data may be retrieved by a process during runtime, such as process 500 of FIG. 5.

FIG. 9B is a flow diagram illustrating one embodiment of a process 900Bfor an application to execute one of multiple executables together witha corresponding source retrieved from an API library based on an APIrequest. In one embodiment, process 900B runs an application program,such as application 103 of FIG. 1, in a data processing system, such asin hosting systems 101 of FIG. 1, including an API library, such ascompute application library 105 of FIG. 1. At block 911, process 900Bmay retrieve a source, such as compute kernel source, and one or morecorresponding executables, such as compute kernel executables, from theAPI library based on API requests, such as process 500 at block 507 ofFIG. 5. Each executable may be associated with one ore more targetphysical computing devices. In one embodiment, a compute kernelexecutable may be backward compatible with multiple versions of physicalcomputing devices. At block 913, process 900B may execute one of theretrieved executables based on an API request in multiple physicalcomputing devices to perform the associated API function, such asprocess 500 at block 517 of FIG. 5. Process 900B may run the applicationat block 909 asynchronously to performing an API function at block 913.

FIG. 10 is sample source code illustrating an example of a computeprogram source code for a compute program executable to be executed inmultiple physical computing devices. Example 1000 may represent an APIfunction with arguments including variables 1001 and streams (or computememory objects) 1003. Example 1000 may be based on a programminglanguage for a parallel computing environment such as system 101 ofFIG. 1. In one embodiment, the parallel programming language may bespecified according to ANSI (American National Standards Institute) Cstandard with additional extensions and restrictions designed toimplement one or more of the embodiments described herein. Theextensions may include a function qualifier, such as qualifier 1005, tospecify a compute kernel function to be executed in a computing device.A compute kernel function may not be called by other compute kernelfunctions. In one embodiment, a compute kernel function may be called bya host function in the parallel program language. A host function may bea regular ANSI C function. A host function may be executed in a hostprocessor separate from the computing device executing a compute kernelfunction. In one embodiment, the extensions may include a localqualifier to describe variables that need to be allocated in a localmemory associated with a computing device to be shared by all threads ofa thread group. The local qualifier may be declared inside a computekernel function. Restrictions of the parallel programming language maybe enforced during compiler time or run time to generate errorconditions, such as outputting error messages or exiting an execution,when the restrictions are violated.

FIGS. 11A-11C include a sample source code illustrating an example toconfigure a logical computing device for executing one of multipleexecutables in multiple physical computing devices by calling APIs.Examples 1100A-1100C may be executed by an application running in a hostsystem attached with multiple physical computing devices, such ashosting systems 101 of FIG. 1. Examples 1100A-1100C may specify a hostfunction of a parallel programming language. Processing operations inexamples 1100A-1100C may be performed as API calls by a process such asprocess 400 of FIG. 4 and/or process 500 of FIG. 5. Processingoperations to create a context object from a computing device, acomputing device group or a logical computing device 1101 may beperformed by the processing logic of process 400 at block 411 of FIG. 4.Processing operations to allocate input/output image memory objects(e.g. compute memory objects) may be performed by the processing logicof process 500 at block 501 of FIG. 1.

Turning now to FIG. 11B, processing operations to allocate and loadarray memory objects 1103 b may be performed by the processing logic ofprocess 500 at block 501 of FIG. 5. The processing operation to create acompute program object 1105 may be performed by the processing logic ofprocess 500 at block 503 of FIG. 5. Processing operation 1107 may load acompute program source, such as example 900 of FIG. 9, to the computeprogram object created. Processing operation 1109 may explicitly build acompute program executable from the loaded compute program source. Inone embodiment, processing operation 1109 may load an already builtcompute program executable to the created compute program object.Subsequently, processing operation 1111 may create a compute kernelobject pointing to the built compute program executable for schedulingan execution on a computing device.

Turing now to FIG. 11C, in one embodiment, processing operation 1113 mayattach variables and compute memory objects as function arguments forthe created compute kernel object. Processing operation 1113 may beperformed by the processing logic of process 500 at block 505 of FIG. 5.Processing operation 1115 may execute the created compute kernel object.In one embodiment, processing operation 1115 may be performed by theprocessing logic of process 500 at block 511 of FIG. 5. Processingoperation 1115 may cause an execution queue to be updated with a computekernel execution instance corresponding to the created compute kernelobject. Processing operation 1117 may synchronously wait for acompletion of executing the create compute kernel object. In oneembodiment, processing operation 1119 may retrieve a result fromexecuting the compute kernel object. Subsequently, processing operations1121 may clean up allocated resources for executing the compute kernelobject, such as an event object, the created compute kernel object andthe allocated memories. In one embodiment, processing operation 1117 maybe performed asynchronously based on whether a kernel event object isset. Processing operation 1117 may be performed by process 500 at block519 of FIG. 5.

FIG. 12 shows one example of a computer system 1200 that can be usedwith one embodiment the present invention. For example, the system 1200may be implemented as a part of the systems shown in FIG. 1. Note thatwhile FIG. 12 illustrates various components of a computer system, it isnot intended to represent any particular architecture or manner ofinterconnecting the components as such details are not germane to thepresent invention. It will also be appreciated that network computersand other data processing systems (for example, handheld computers,personal digital assistants (PDAs), cellular telephones, entertainmentsystems, consumer electronic devices, etc.) which have fewer componentsor perhaps more components may also be used with to implement one ormore embodiments of the present invention.

As shown in FIG. 12, the computer system 1200, which is a form of a dataprocessing system, includes a bus 1203 which is coupled to amicroprocessor(s) 1205, such as CPUs and/or GPUs, a ROM (Read OnlyMemory) 1207, volatile RAM 1209 and a non-volatile memory 1211. Themicroprocessor 1205 may retrieve the instructions from the memories1207, 1209, 1211 and execute the instructions using Cache 1221 toperform operations described above. The bus 1203 interconnects thesevarious components together and also interconnects these components1205, 1207, 1209, and 1211 to a display controller and display device1213 and to peripheral devices such as input/output (I/O) devices whichmay be mice, keyboards, modems, network interfaces, printers and otherdevices which are well known in the art. Typically, the input/outputdevices 915 are coupled to the system through input/output controllers1217. The volatile RAM (Random Access Memory) 1209 is typicallyimplemented as dynamic RAM (DRAM) which requires power continually inorder to refresh or maintain the data in the memory. The displaycontroller coupled with a display device 1213 may optionally include oneor more GPUs to process display data. Optionally, GPU memory 1219 may beprovided to support GPUs included in the display device 1213.

The mass storage 1211 is typically a magnetic hard drive or a magneticoptical drive or an optical drive or a DVD RAM or a flash memory orother types of memory systems which maintain data (e.g. large amounts ofdata) even after power is removed from the system. Typically, the massstorage 1211 will also be a random access memory although this is notrequired. While FIG. 12 shows that the mass storage 1211 is a localdevice coupled directly to the rest of the components in the dataprocessing system, it will be appreciated that the present invention mayutilize a non-volatile memory which is remote from the system, such as anetwork storage device which is coupled to the data processing systemthrough a network interface such as a modem or Ethernet interface orwireless networking interface. The bus 1203 may include one or morebuses connected to each other through various bridges, controllersand/or adapters as is well known in the art.

Portions of what was described above may be implemented with logiccircuitry such as a dedicated logic circuit or with a microcontroller orother form of processing core that executes program code instructions.Thus processes taught by the discussion above may be performed withprogram code such as machine-executable instructions that cause amachine that executes these instructions to perform certain functions.In this context, a “machine” may be a machine that converts intermediateform (or “abstract”) instructions into processor specific instructions(e.g., an abstract execution environment such as a “virtual machine”(e.g., a Java Virtual Machine), an interpreter, a Common LanguageRuntime, a high-level language virtual machine, etc.), and/or,electronic circuitry disposed on a semiconductor chip (e.g., “logiccircuitry” implemented with transistors) designed to executeinstructions such as a general-purpose processor and/or aspecial-purpose processor. Processes taught by the discussion above mayalso be performed by (in the alternative to a machine or in combinationwith a machine) electronic circuitry designed to perform the processes(or a portion thereof) without the execution of program code.

An article of manufacture may be used to store program code, forexample, including multiple tokens. An article of manufacture thatstores program code may be embodied as, but is not limited to, one ormore memories (e.g., one or more flash memories, random access memories(static, dynamic or other)), optical disks, CD-ROMs, DVD ROMs, EPROMs,EEPROMs, magnetic or optical cards or other type of machine-readablemedia suitable for storing electronic instructions. Program code mayalso be downloaded from a remote computer (e.g., a server) to arequesting computer (e.g., a client) by way of data signals embodied ina propagation medium (e.g., using a communication link (e.g., a networkconnection)).

The preceding detailed descriptions are presented in terms of algorithmsand symbolic representations of operations on data bits within acomputer memory. These algorithmic descriptions and representations arethe tools used by those skilled in the data processing arts to mosteffectively convey the substance of their work to others skilled in theart. An algorithm is here, and generally, conceived to be aself-consistent sequence of operations leading to a desired result. Theoperations are those requiring physical manipulations of physicalquantities. Usually, though not necessarily, these quantities take theform of electrical or magnetic signals capable of being stored,transferred, combined, compared, and otherwise manipulated. It hasproven convenient at times, principally for reasons of common usage, torefer to these signals as bits, values, elements, symbols, characters,terms, numbers, or the like.

It should be kept in mind, however, that all of these and similar termsare to be associated with the appropriate physical quantities and aremerely convenient labels applied to these quantities. Unlessspecifically stated otherwise as apparent from the above discussion, itis appreciated that throughout the description, discussions utilizingterms such as “processing” or “computing” or “calculating” or“determining” or “displaying” or the like, refer to the action andprocesses of a computer system, or similar electronic computing device,that manipulates and transforms data represented as physical(electronic) quantities within the computer system's registers andmemories into other data similarly represented as physical quantitieswithin the computer system memories or registers or other suchinformation storage, transmission or display devices.

The present invention also relates to an apparatus for performing theoperations described herein. This apparatus may be specially constructedfor the required purpose, or it may comprise a general-purpose computerselectively activated or reconfigured by a computer program stored inthe computer. Such a computer program may be stored in a computerreadable storage medium, such as, but is not limited to, any type ofdisk including floppy disks, optical disks, CD-ROMs, andmagnetic-optical disks, read-only memories (ROMs), RAMs, EPROMs,EEPROMs, magnetic or optical cards, or any type of media suitable forstoring electronic instructions, and each coupled to a computer systembus.

The processes and displays presented herein are not inherently relatedto any particular computer or other apparatus. Various general-purposesystems may be used with programs in accordance with the teachingsherein, or it may prove convenient to construct a more specializedapparatus to perform the operations described. The required structurefor a variety of these systems will be evident from the descriptionbelow. In addition, the present invention is not described withreference to any particular programming language. It will be appreciatedthat a variety of programming languages may be used to implement theteachings of the invention as described herein.

The foregoing discussion merely describes some exemplary embodiments ofthe present invention. One skilled in the art will readily recognizefrom such discussion, the accompanying drawings and the claims thatvarious modifications can be made without departing from the spirit andscope of the invention.

What is claimed is:
 1. A computerized method comprising: receiving, froma host application executing on a host processor, a request to create acompute program corresponding to source code for a task in the hostapplication; creating the compute program for execution on a computedevice selected by the host application from one or more computeidentifiers received in a request from the host application to identifycompute devices that match a processing requirement for the task;receiving, from the host application, a request to create a computekernel containing executable code for the task; and creating the computekernel.